//用户
import request from '@/utils/request'
import type { UserReq, UserData, RoleAdd } from './type'
enum API {
  USERLIST_URL = '/admin/acl/user',
  //添加
  ADDUSER_URL = '/admin/acl/user/save',
  // 详情
  DETAILUSER_URL = '/admin/acl/user/get/',
  // 修改
  UPDATEUSER_URL = '/admin/acl/user/update',
  //删除
  DELETETUSER_URL = '/admin/acl/user/remove/',
  //获取全部职位,当前账号拥有的职位接口

  ADDUSERROLE_URL = '/admin/acl/user/toAssign',
    //给已有的用户分配角色接口
  USERROLE_URL = '/admin/acl/user/doAssignRole',
    //批量删除的接口
    DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}
export const reqUserList = (page: number, limit: number, username: string) =>
  request.get<any, UserReq>(API.USERLIST_URL + `/${page}/${limit}?username=${username}`, )

export const reqDeleteUser = (id: number) =>
  request.delete<any, any>(API.DELETETUSER_URL + id)

export const reqAddOrUpdateUser = (data: UserData) => {
  //新增
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}

//删除
export const reqDetailUser = (id: number) =>
  request.get<any, any>(API.DETAILUSER_URL + id)

export const reqUserRole = (data: RoleAdd) =>
  request.post<any, any>(API.USERROLE_URL,data)
export const addUserRole = (id: number) =>
  request.get<any, any>(API.ADDUSERROLE_URL + '/' + id)
  export const reqSelectUser = (idList: number[]) =>
  request.delete(API.DELETEALLUSER_URL, { data: idList })
